package com.banshuibao.bsb_android.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.model.ExpertTreeModel;
import com.banshuibao.bsb_android.util.XToast;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangpan on 2018/3/5.
 */

public class MenuShowGridAdapter extends BaseAdapter {
    Context context;
    List<ExpertTreeModel.DataBean.ChildrenBean> list;

    public MenuShowGridAdapter(Context context) {
        this.context = context;
        list = new ArrayList<>();
    }

    public void setData(List<ExpertTreeModel.DataBean.ChildrenBean> list) {
        if (list == null) {
            XToast.showToast(context, "空值");
            return;
        }
        if (this.list != null) {
            this.list.clear();
            this.list.addAll(list);
            notifyDataSetChanged();
        }
    }

    @Override
    public int getCount() {
        return list != null ? list.size() : 0;
    }

    @Override
    public ExpertTreeModel.DataBean.ChildrenBean getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            viewHolder = new ViewHolder();
            view = View.inflate(context, R.layout.menu_tag_layout, null);
            viewHolder.textView = view.findViewById(R.id.text_tag);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.textView.setText(list.get(i).getName().trim());
        return view;
    }

    public class ViewHolder {
        TextView textView;
    }
}
